package com.ruoyi.web.controller.mall.goodsBrand.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.controller.mall.goodsBrand.domain.GoodsBrand;
import com.ruoyi.web.controller.mall.goodsBrand.service.IGoodsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品品牌Controller
 * 
 * @author ruoyi
 * @date 2021-01-18
 */
@Controller
@RequestMapping("/mall/goodsBrand")
public class GoodsBrandController extends BaseController
{
    private String prefix = "mall/goodsBrand";

    @Autowired
    private IGoodsBrandService goodsBrandService;

//    @RequiresPermissions("mall:goodsBrand:view")
    @GetMapping()
    public String goodsBrand()
    {
        return prefix + "/goodsBrand";
    }

    /**
     * 查询商品品牌列表
     */
//    @RequiresPermissions("mall:goodsBrand:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GoodsBrand goodsBrand)
    {
        startPage();
        List<GoodsBrand> list = goodsBrandService.selectGoodsBrandList(goodsBrand);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌列表
     */
//    @RequiresPermissions("mall:goodsBrand:export")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsBrand goodsBrand)
    {
        List<GoodsBrand> list = goodsBrandService.selectGoodsBrandList(goodsBrand);
        ExcelUtil<GoodsBrand> util = new ExcelUtil<GoodsBrand>(GoodsBrand.class);
        return util.exportExcel(list, "goodsBrand");
    }

    /**
     * 新增商品品牌
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品品牌
     */
//    @RequiresPermissions("mall:goodsBrand:add")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GoodsBrand goodsBrand)
    {
        return toAjax(goodsBrandService.insertGoodsBrand(goodsBrand));
    }

    /**
     * 修改商品品牌
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GoodsBrand goodsBrand = goodsBrandService.selectGoodsBrandById(id);
        mmap.put("goodsBrand", goodsBrand);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品品牌
     */
//    @RequiresPermissions("mall:goodsBrand:edit")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GoodsBrand goodsBrand)
    {
        return toAjax(goodsBrandService.updateGoodsBrand(goodsBrand));
    }

    /**
     * 删除商品品牌
     */
//    @RequiresPermissions("mall:goodsBrand:remove")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String[] ids)
    {
        return toAjax(goodsBrandService.deleteGoodsBrandByIds(ids));
    }
}
